package org.ruanjj.multithread.JUC;
import java.util.concurrent.Semaphore;
public class SemaphoreDemo {
    public static void main(String[] args) {
        Semaphore semaphore = new Semaphore(3);

        for(int i = 1 ; i <=6; i++){
            new Thread(()->{
                try {
                    semaphore.acquire();
                    System.out.println(Thread.currentThread().getName()+"车进来停车");
                    Thread.sleep(1000);
                    System.out.println(Thread.currentThread().getName()+"离开了。。。。");
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }finally {
                    semaphore.release();
                }


            },String.valueOf(i)).start();
        }
    }

}
